package com.example.jetpacktest.navigation

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation

import com.example.jetpacktest.R
import kotlinx.android.synthetic.main.fragment_fragment1.view.*


/**
 */
class Fragment1 : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        var view = inflater.inflate(R.layout.fragment_fragment1, container, false)
//        跳转方式1
//        view.jump?.setOnClickListener {
//            Navigation.findNavController(it).navigate(R.id.action_fragment1_to_fragment2)
//        }

//        跳转方式2，直接给setOnClickListener添加
//        view.jump?.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_fragment1_to_fragment2))


//        常规传递参数
//        view.jump?.setOnClickListener {
//            var bundle = Bundle()
//            bundle.putString("name", "张三")
//            bundle.putInt("age", 18)
//            Navigation.findNavController(it).navigate(R.id.action_fragment1_to_fragment2, bundle)
//        }

        //safe-args传递参数
        view.jump?.setOnClickListener {
            var bundle = Fragment1Args.Builder().setUserage(18).setUsername("李四").build().toBundle()

            Navigation.findNavController(it).navigate(R.id.action_fragment1_to_fragment2, bundle)
        }
        return view
    }

}
